﻿<#include "/@inc/copyright.txt">
<#assign className = LateType + "Form">
<@pp.renameOutputFile name=className+".cs">
</@pp.renameOutputFile>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ${LateType}Modeler;

namespace ${LateType}UI
{
    public partial class ${className} : Form
    {
        private ${LateType} _${LateType} ;
        public ${className}()
        {
            _${LateType} = new ${LateType}Modeler.${LateType}();

            InitializeComponent();
        }

	<#list AttributesUI as attrib>
	<#switch attrib.UI>
	<#case "Button">
	<#case "RadioButton">
        private void On${attrib.name}(object sender, EventArgs e)
        {
		<#if attrib.name == "OK">
		<#list Attributes as attrUI>
		<#switch attrUI.UI>
		<#case "Button">
		<#case "Label">
		<#case "LinkLabel">
		<#break>
		<#case "CheckBox">
		<#case "RadioButton">
			_${LateType}.${attrUI.name} = _${attrUI.UI}${attrUI.name}.Checked;
		<#break>
		<#case "MonthCalendar">
		<#if attrUI.type == "DateTime">
			_${LateType}.${attrUI.name} = _${attrUI.UI}${attrUI.name}.SelectionRange.Start ;
		<#elseif attrUI.type == "List<DateTime>" >
            for (DateTime date = _${attrUI.UI}${attrUI.name}.SelectionRange.Start;  date < _${attrUI.UI}${attrUI.name}.SelectionRange.End ;
					date = date.AddDays(1.0) )
            {
                _${LateType}.${attrUI.name}.Add(date);
            }
		</#if>
		<#break>
		<#case "ComboBox">
			_${LateType}.${attrUI.name} = _${attrUI.UI}${attrUI.name}.SelectedText;
		<#break>
		<#case "DateTimePicker">
		<#case "RichTextBox">
		<#case "TextBox">
		<#if attrUI.type == "string">
			_${LateType}.${attrUI.name} = _${attrUI.UI}${attrUI.name}.Text;
		<#elseif attrUI.type == "List<string>" >
			String [] token${attrUI.name} = _${attrUI.UI}${attrUI.name}.Text.Split('\n');
            foreach (var item in token${attrUI.name})
            {
                _${LateType}.${attrUI.name}.Add(item);
            }
		</#if>
		<#break>
		<#case "NumericUpDown">
			_${LateType}.${attrUI.name} = (${attrUI.type}) _${attrUI.UI}${attrUI.name}.Value;
		<#break>
		<#default>
			//_${LateType}.${attrUI.name} = _${attrUI.UI}${attrUI.name}.Value;
		<#break>
		</#switch>
		</#list>
		_${LateType}.Run() ;
		this.Close();
		<#elseif ( attrib.data?size > 0 ) &&  attrib.data[0]?string == "OpenFileDialog" >
			this._OpenFileDialog${attrib.name}.ShowDialog();
		</#if>
        }
	<#break>
	<#case "CheckBox">
        private void OnCheck${attrib.name}(object sender, EventArgs e)
        {
            //_${attrib.UI}${attrib.name};
            MessageBox.Show("You clicked ${attrib.UI} ${attrib.name}") ;
        }
	<#break>
	<#case "OpenFileDialog">
        private void OnOK${attrib.name}(object sender, EventArgs e)
        {
            _${LateType}.${attrib.name} = _${attrib.UI}${attrib.name}.FileName;
            MessageBox.Show("You selected " + _${attrib.UI}${attrib.name}.FileName ) ;
        }
	<#break>
	<#case "ComboBox">
        private void OnSelect${attrib.name}(object sender, EventArgs e)
        {
            //_${attrib.UI}${attrib.name};
            MessageBox.Show("You clicked ${attrib.UI} ${attrib.name}") ;
        }
	<#break>
	</#switch>
	</#list>

        // private void OnOpenOK(object sender, CancelEventArgs e)
        // {
        // }

    }
}
